<?php
/**
 * 下载类
 * edit by gemj
 * 2011－08－06
 */

class EAdmin_Page_Down extends EAdmin_Page_Abstract
{
	public function validate(ME_Request $input, ME_Response $output)
	{
		$state = ME_Config::get("ResumeState");
		$input->eduDegree = $eduDegree = $state['eduDegree'];

		return true;
	}

	public function doDefault(ME_Request $input, ME_Response $output)
	{
		$eduDegree = $input->eduDegree;

		$id_str = $input->get("idStr");

		if(strlen($id_str) > 0){
			$id_str = str_replace("_",",",$id_str);
			$resumeDb = Db_Resume::instance();
			$commonOption = array(
					'db'        => $resumeDb,
					'fromSql'   => 'from resume_baseInfo',
					'whereSql'  => "where uid in ({$id_str})",
					'onlyData'  => true,
					'debug'     => false,
					);
			$output->baseinfoList = 
				$baseinfoList = Libs_DBHelper::getList($commonOption);

			$commonOption = array(
					'db'        => $resumeDb,
					'fromSql'   => 'from resume_edu',
					'whereSql'  => "where uid in ({$id_str})",
					'onlyData'  => true,
					'debug'     => false,
					);
			$eduList = Libs_DBHelper::getList($commonOption);
			$newEduList = array();
			if($eduList){
				foreach($eduList as $eduinfo){
					$edu_uid = $eduinfo['uid'];
					$newEduList[$edu_uid] = $eduinfo;
				}	
			}
/**
			$commonOption = array(
					'db'        => $resumeDb,
					'fromSql'   => 'from resume_school',
					'whereSql'  => "where uid in ({$id_str})",
					'onlyData'  => true,
					'debug'     => false,
					);
			$schoolList = Libs_DBHelper::getList($commonOption);
			$newSchoolList = array();
			if($newSchoolList){
				foreach($newSchoolList as $schoolinfo){
					$school_uid = $schoolinfo['uid'];
					$newSchoolList[$school_uid] = $schoolinfo;
				}	
			}
**/
			$kn2 = array(
				"id"=>"ID",
				"name"=>"姓名",
				"school"=>"毕业院校",
				"major"=>"专业",
				"degree"=>"学位",
				"school_time"=>"就读时间",
				"birthday"=>"出生日期",
				"reg_city"=>"所在地",
				"mobile"=>"手机号"
			);

			$xls[] = implode(",", array_values($kn2));
			if($baseinfoList){
				foreach($baseinfoList as $baseinfo){
					$eduinfo = array();
					$uid = $baseinfo['uid'];
					$degree = $baseinfo['degree'];
					if(array_key_exists($uid,$newEduList)){
						$eduinfo = $newEduList[$uid];
					}

					$sql = "select name from category_list where module_type=1 and classid={$baseinfo['regProv']} and subclassid={$baseinfo['regCity']} limit 1";
					$reg_city = $resumeDb->getOne($sql);

					if($eduinfo['startYear']){
						$schoolEnd = $eduinfo['endYear'] == 0 ? '~' : $eduinfo['endYear'].'-'.$eduinfo['endMonth'];
						$schoolRange = $eduinfo['startYear'].'-'.$eduinfo['startMonth'].'至'.$schoolEnd;
					}else{
						$schoolRange = '';	
					}

					$xls[] = $uid.','.$baseinfo['trueName'].','.$eduinfo['schoolName'].','.$eduinfo['majorName'].','.$eduDegree['degree'].','.$schoolRange.','.$baseinfo['birthYear'].'-'.$baseinfo['birthMonth'].'-'.$baseinfo['birthDay'].','.$reg_city.','.$baseinfo['mobile'];
				}
			}
			$xls = join("\r\n", $xls);
			header('Content-Disposition: attachment; filename="resume.csv"');
			die(mb_convert_encoding($xls,'GBK','UTF-8'));

		}
	}

}
